package ihm;
import java.awt.AWTException;
import java.awt.Panel;
import java.awt.Robot;
import java.awt.event.*; 
import javax.swing.*;

import struct.Cercle;
import struct.Mur;
import struct.Triangle;
import struct.Pong;

import java.awt.event.ActionListener;
 
public class MenuBar implements ActionListener{
	
	

private Window win;


  private JMenuBar menuBar = new JMenuBar();
  private JMenu fichier = new JMenu("Fichier");
  private JMenu edition = new JMenu("Edition");
 


  private JMenuItem creerNouvelleForme = new JMenuItem("Creer une nouvelle forme");
  private JMenuItem fermer = new JMenuItem("Fermer");
 
  private JMenuItem effacerFenetre = new JMenuItem("Remettre a zero la fenetre");
  private JMenuItem execute = new JMenuItem("Executer animation");
  
  private Thread t;
 
  public MenuBar(Window _win)
  {
  	this.win=_win;

 
    // MENU FICHIER
    this.fichier.add(this.creerNouvelleForme);
    this.fichier.addSeparator();
    this.fichier.add(this.fermer);
    
    creerNouvelleForme.addActionListener(this);    
    fermer.addActionListener(this);


    this.menuBar.add(fichier);

    // MENU EDITION
    
    this.edition.add(this.effacerFenetre);
    this.edition.add(this.execute);
    
    effacerFenetre.addActionListener(this);
    execute.addActionListener(this);
    
    this.menuBar.add(edition);
  }
  
  public void actionPerformed(ActionEvent arg){


  	if (arg.getSource()==creerNouvelleForme){
  		NewForm newform = new NewForm("Creation d'une nouvelle forme", this.win);
  	}
  	if (arg.getSource()==fermer){
          System.exit(0);
  	}	
  	
  	if (arg.getSource()==effacerFenetre){
  		win.effacerFenetre();
  	}
  	
  	class PlayAnimation implements Runnable{
  	    public void run() {
  	    
  	      win.executeAnim();                   
  	    }               
  	  }   
  	
  	if (arg.getSource()==execute){
       t = new Thread(new PlayAnimation());
       t.start();
  	}
  }
   
    public JMenuBar getMenuBar() {
        return menuBar;
    }  
}